package Presentacion.contabilidad;

import clases.contabilidad.Cuenta;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author RICHARD
 */
public class dlgConsultaCuenta extends javax.swing.JDialog {

    public String descripcion;
    public String id;
    private static dlgCuenta cuenta;
    private static dlgAsiento asiento;
    private static dlgConcepto concepto;
    private static String sql;
    private static int pagina;
    private static Cuenta objCuenta;

    /**
     * Creates new form ConsultaCuenta
     *
     * @param parent
     * @param modal
     */
    public dlgConsultaCuenta(dlgCuenta parent, boolean modal) {
        cuenta = parent;
        setModal(modal);
        initComponents();
        setLocationRelativeTo(this);
        setResizable(false);
        pagina = 1;
        objCuenta = new Cuenta();
        sql = objCuenta.SqlGeneral();
        generartabla();
    }

    public dlgConsultaCuenta(dlgAsiento parent, boolean modal) {
        asiento = parent;
        setModal(modal);
        initComponents();
        setLocationRelativeTo(this);
        setResizable(false);
        pagina = 1;
        objCuenta = new Cuenta();
        sql = objCuenta.SqlGeneral();
        generartabla();
    }

    public dlgConsultaCuenta(dlgConcepto parent, boolean modal) {
        concepto = parent;
        setModal(modal);
        initComponents();
        setLocationRelativeTo(this);
        setResizable(false);
        pagina = 1;
        objCuenta = new Cuenta();
        sql = objCuenta.SqlGeneral();
        generartabla();
    }

    private static void generartabla() {
        objCuenta.llenarTabla(new DefaultTableModel(), tblcuenta,
                sql, lbltotalpaginas, lblpagina, pagina);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtbuscar = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblcuenta = new javax.swing.JTable();
        btnactivo = new javax.swing.JButton();
        btnpasivo = new javax.swing.JButton();
        btnpatrimonio = new javax.swing.JButton();
        btningreso = new javax.swing.JButton();
        btngastos = new javax.swing.JButton();
        jToolBar1 = new javax.swing.JToolBar();
        btnprimero = new javax.swing.JButton();
        btnatras = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jLabel4 = new javax.swing.JLabel();
        lblpagina = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        lbltotalpaginas = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        btnsiguiente = new javax.swing.JButton();
        btnultimo = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("BUSCAR");

        txtbuscar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtbuscarKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtbuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtbuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        tblcuenta.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblcuenta.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblcuentaMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblcuenta);

        btnactivo.setText("Activo");
        btnactivo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnactivoActionPerformed(evt);
            }
        });

        btnpasivo.setText("Pasivo");
        btnpasivo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnpasivoActionPerformed(evt);
            }
        });

        btnpatrimonio.setText("Patrimonio");
        btnpatrimonio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnpatrimonioActionPerformed(evt);
            }
        });

        btningreso.setText("Ingresos");
        btningreso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btningresoActionPerformed(evt);
            }
        });

        btngastos.setText("Gastos");
        btngastos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btngastosActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btngastos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnactivo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnpasivo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                    .addComponent(btnpatrimonio, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                    .addComponent(btningreso, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 646, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btnactivo, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnpasivo, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnpatrimonio, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btningreso, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btngastos, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jToolBar1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        btnprimero.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/primer.png"))); // NOI18N
        btnprimero.setFocusable(false);
        btnprimero.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnprimero.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnprimero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnprimeroActionPerformed(evt);
            }
        });
        jToolBar1.add(btnprimero);

        btnatras.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/atras.png"))); // NOI18N
        btnatras.setToolTipText("");
        btnatras.setFocusable(false);
        btnatras.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnatras.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnatras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnatrasActionPerformed(evt);
            }
        });
        jToolBar1.add(btnatras);
        jToolBar1.add(jSeparator1);

        jLabel4.setText("Pagina ");
        jToolBar1.add(jLabel4);

        lblpagina.setText("jLabel2");
        jToolBar1.add(lblpagina);

        jLabel5.setText(" de ");
        jToolBar1.add(jLabel5);

        lbltotalpaginas.setText("jLabel1");
        jToolBar1.add(lbltotalpaginas);
        jToolBar1.add(jSeparator2);

        btnsiguiente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/siguiente.png"))); // NOI18N
        btnsiguiente.setFocusable(false);
        btnsiguiente.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnsiguiente.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnsiguiente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnsiguienteActionPerformed(evt);
            }
        });
        jToolBar1.add(btnsiguiente);

        btnultimo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/ultimos.png"))); // NOI18N
        btnultimo.setFocusable(false);
        btnultimo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnultimo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnultimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnultimoActionPerformed(evt);
            }
        });
        jToolBar1.add(btnultimo);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnprimeroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnprimeroActionPerformed
        pagina = 1;
        generartabla();
    }//GEN-LAST:event_btnprimeroActionPerformed

    private void btnatrasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnatrasActionPerformed
        if (pagina > 1) {
            pagina--;
            generartabla();
        }
    }//GEN-LAST:event_btnatrasActionPerformed

    private void btnsiguienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnsiguienteActionPerformed
        if (objCuenta.objPaginacion.getTotalpaginas() > pagina) {
            pagina++;
            generartabla();
        }
    }//GEN-LAST:event_btnsiguienteActionPerformed

    private void btnultimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnultimoActionPerformed
        pagina = objCuenta.objPaginacion.getTotalpaginas();
        generartabla();
    }//GEN-LAST:event_btnultimoActionPerformed

    private void txtbuscarKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtbuscarKeyReleased
        global.Validaciones.convertirMayuscula(txtbuscar);
        if (global.Validaciones.comprobarNulo(txtbuscar)) {
            pagina = 1;
            sql = objCuenta.SqlBuscar(txtbuscar.getText());
            generartabla();
        } else {
            pagina = 1;
            sql = objCuenta.SqlGeneral();
            generartabla();
        }

    }//GEN-LAST:event_txtbuscarKeyReleased

    private void tblcuentaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblcuentaMouseClicked
        int click = evt.getClickCount();
        if (click == 2) {
            descripcion = tblcuenta.getValueAt(tblcuenta.getSelectedRow(), 1).toString();
            id = tblcuenta.getValueAt(tblcuenta.getSelectedRow(), 0).toString();
            dispose();
        }

    }//GEN-LAST:event_tblcuentaMouseClicked

    private void btnactivoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnactivoActionPerformed
        pagina = 1;
        sql = objCuenta.SqlConsulta("ACTIVO");
        generartabla();

    }//GEN-LAST:event_btnactivoActionPerformed

    private void btnpasivoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnpasivoActionPerformed
        pagina = 1;
        sql = objCuenta.SqlConsulta("PASIVO");
        generartabla();

    }//GEN-LAST:event_btnpasivoActionPerformed

    private void btnpatrimonioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnpatrimonioActionPerformed
        pagina = 1;
        sql = objCuenta.SqlConsulta("PATRIMONIO");
        generartabla();

    }//GEN-LAST:event_btnpatrimonioActionPerformed

    private void btningresoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btningresoActionPerformed
        pagina = 1;
        sql = objCuenta.SqlConsulta("INGRESOS");
        generartabla();

    }//GEN-LAST:event_btningresoActionPerformed

    private void btngastosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btngastosActionPerformed
        pagina = 1;
        sql = objCuenta.SqlConsulta("GASTOS");
        generartabla();

    }//GEN-LAST:event_btngastosActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(dlgConsultaCuenta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(dlgConsultaCuenta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(dlgConsultaCuenta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(dlgConsultaCuenta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                dlgConsultaCuenta dialog = new dlgConsultaCuenta(cuenta, true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnactivo;
    private javax.swing.JButton btnatras;
    private javax.swing.JButton btngastos;
    private javax.swing.JButton btningreso;
    private javax.swing.JButton btnpasivo;
    private javax.swing.JButton btnpatrimonio;
    private javax.swing.JButton btnprimero;
    private javax.swing.JButton btnsiguiente;
    private javax.swing.JButton btnultimo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar jToolBar1;
    private static javax.swing.JLabel lblpagina;
    private static javax.swing.JLabel lbltotalpaginas;
    private static javax.swing.JTable tblcuenta;
    private javax.swing.JTextField txtbuscar;
    // End of variables declaration//GEN-END:variables
}
